import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        double NumberA,NumberB;
        String operate;
        System.out.println("请输入数字A,B,符号(+,-,*,/)");
        Scanner input = new Scanner(System.in);
        NumberA = input.nextDouble();
        NumberB = input.nextDouble();
        operate = input.next();
        // 业务逻辑代码,面向对象动态多态
        // 功能：根据具体的运算符号确定实例化（“生产”）运算类的对象
        Operation opr = null;
        Factory factory = null;
        // switch功能为：根据运算符号确定实例化相应的工厂对象
        switch (operate) {
            case "+":
                factory = new AddFactory();
                break;
            case "-":
                factory = new SubFactory();
                break;
            case "/":
                factory = new DivFactory();
                break;
            default:
                try {
                    throw new Exception("输入错误！");
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
        }
        double result;
        // 获取具体的运算类对象
        opr = factory.getOperation();
        opr.setValue(NumberA, NumberB);
        // 进行具体的运算
        result = opr.getResult();

        // 界面逻辑代码--控制台界面
        System.out.println("结果为：" + result);
    }
}
